package com.nxy.cpfsfe.busi.unfyag;

import com.adtec.starring.datapool.CompSDO;
import com.adtec.starring.datapool.EPOper;
import com.adtec.starring.struct.dta.DtaInfo;
import com.nxy.cpfsfe.enumtype.RespCd;
import com.nxy.cpfsfe.service.CpfsService;
import com.nxy.cpfsfe.util.ResponseUtil;
import com.nxy.cpfsfe.util.XmlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * Description汇兑支付同步流程
 * Created by nxygyzd on 2019/11/25.
 */
public class RmPSrvBean implements CpfsService {
    private final static Logger LOGGER = LoggerFactory.getLogger(RmPSrvBean.class);

    @Override
    public void doService() {
        LOGGER.debug("---------汇兑支付CPFS100业务开始---------");
        Map<String,String> map = new HashMap<>();
        String tpId = DtaInfo.getInstance().getTpId();
        // 获取输入
        CompSDO inputSdo = (CompSDO) EPOper.getCompSDO(tpId, "ReqBody"); // 获取输入接口
        // 获取输出
        CompSDO outputSdo = EPOper.getCompSDO(tpId, "RspBody"); // 获取输出接口
        try {
            EPOper.put(tpId, "RspBean[0].head[0].rspsCd", RespCd.NCPS7001);
            EPOper.put(tpId, "RspBean[0].head[0].respsInfoDesc", "汇兑支付交易失败");
            String nginxUrl = (String)EPOper.get(tpId, "RspBean[0].head[0].iPAddr");
            String bizMsg = (String) inputSdo.getValue("BizMsg")!=null?(String) inputSdo.getValue("BizMsg"):""; // 业务报文
            LOGGER.info("nginxUrl地址[{}],业务报文：[{}]",nginxUrl,bizMsg);
            //生成业务map
            map.put("resultCode",RespCd.NCPI0000);
            map.put("msg", "成功");
        }catch (Exception e) {
            LOGGER.error("同步响应汇兑支付信息失败",e);
            map.put("msg", "同步响应汇兑支付信息失败");
            map.put("resultCode",RespCd.NCPO3999);
        }finally{
//            String bizMsgResult = ResponseUtil.buildXmlGeneral(map);
            ResponseUtil.responseSend("",map);
        }
        LOGGER.debug("---------汇兑支付业务同步响应成功---------");
    }
}
